<template>
	<view class="container" v-if="show">
		<uni-nav-bar left-icon="back" @clickLeft="back" fixed="true" status-bar="true" title="商户分类">
		</uni-nav-bar>
		<!-- #ifdef MP-WEIXIN -->
		<view class="category-list" :style="{top:fixedTop + 'px'}">
		<!-- #endif -->
		<!-- #ifdef APP-PLUS -->
		<view class="category-list">
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<view class="category-list">
		<!-- #endif -->
			<!-- 左侧分类导航 -->
			<scroll-view scroll-y="true" class="left">
				<view class="row" v-for="(category,index) in categoryList" :key="category.sc_id" :class="[index==showCategoryIndex?'on':'']"
				 @tap="showCategory(index)">
					<view class="text">
						<view class="block"></view>
						{{category.sc_name}}
					</view>
				</view>
			</scroll-view>
			<!-- 右侧子导航 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category" v-for="(category,index) in categoryList" :key="category.sc_id" v-show="index==showCategoryIndex">
					<view class="list">
						<view class="box" v-for="(box,i) in category.son" :key="i" @tap="toCategory(box.sc_name,box.sc_id)">
							<image :src="box.sc_image"></image>
							<view class="text">{{box.sc_name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import {
		getsellerclass
	} from "@/api/merchant.js"
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	export default {
		components: {
			uniNavBar
		},
		props: {
			show: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// #ifdef MP-WEIXIN
				fixedTop: getApp().globalData.MenuButtonTop + 38,
				// #endif
				showCategoryIndex: 0,
				//分类列表
				categoryList: [],
			}
		},
		mounted() {
			getsellerclass().then(res => {
				this.categoryList = res.data.seller_class
			})
		},
		methods: {
			//分类切换显示
			showCategory(index) {
				this.showCategoryIndex = index;
			},
			toCategory(name, id) {
				this.$emit('select', {
					name: name,
					id: id
				})
			},
			back() {
				this.$emit('back', false)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.container {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background-color: #fff;
		z-index: 9999999999;
	}

	.category-list {
		border-top: 1rpx solid #f5f5f5;
		// #ifdef APP-PLUS
		top: calc(var(--status-bar-height) + 44px);
		// #endif
		// #ifdef H5
		top: 44px;
		// #endif
		width: 100%;
		background-color: #fff;
		display: flex;
		position: absolute;
		bottom: 0upx;

		.left {
			width: 24%;
			left: 0upx;
			background-color: #f2f2f2;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;

				.text {
					width: 100%;
					position: relative;
					font-size: 28upx;
					display: flex;
					justify-content: center;
					color: #3c3c3c;

					.block {
						position: absolute;
						width: 0upx;
						left: 0;
					}
				}

				&.on {
					height: 100upx;
					background-color: #fff;

					.text {
						font-size: 30upx;
						font-weight: 600;
						color: #2d2d2d;

						.block {
							width: 10upx;
							height: 80%;
							top: 10%;
							background-color: #f06c7a;
						}
					}
				}
			}
		}

		.right {
			width: 76%;
			left: 24%;

			.category {
				width: 94%;
				padding: 20upx 3%;

				.list {
					margin-top: 40upx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.box {
						width: calc(71.44vw / 3);
						margin-bottom: 30upx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 60%;
							height: calc(71.44vw / 3 * 0.6);
						}

						.text {
							margin-top: 5upx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
						}
					}
				}
			}
		}
	}
</style>
